


//var pageContext = new PageContext(settings||{});

function PageContextTable(settings){
	PageContext.call(this, settings);
	var _this = this; //把this保存下来，以后用_this代替this，这样就不会被this弄晕了
	
	this.formInit = function(layero) {
		
	}; 
	this.reset = function (){
		$("#"+_this.setting.formId).clearForm(); 
	}
	this.search = function() {// 搜索
		var from = $("#" + _this.setting.formId);
		if (from.validationEngine("validate")) {
			var searchParames = '';
			searchParames = from.formSerializeNotBlank();
		}
		from.submit();
	};
	this.getCheckedIds = function() {// 获取表格选中的id
		var records = _this.getCheckedRecords();
		var ids = new Array();
		if (records) {
			for (var i = 0; i < records.length; i++) {
				ids.push(records[i].id);
			}
		}
		return ids.join(",");
	};
	this.getCheckedRecords = function() {// 获取表格选中的项
		var records = new Array();
		$('#' + _this.setting.tableId + ' tbody tr').each(function() {
			var trControl = $(this).find('input[class*="trControl"]');
			if (trControl.length == 1) {
				if ($(trControl.get(0)).prop("checked") == true) {
					records[records.length] = {
						id : $(this).attr("val")
					};
				}
			}
		});
		return records;
	};
	this.refushOperTdClass = function() {
		var tds = $(
				$("#" + _this.setting.tableId + " tbody tr .operBtn"))
				.parent('div').parent('div').parent('td');
		tds.removeClass("lineNoWrap").addClass("lineNoWrapOper");
	};
	
	this.deleteItemAfter=function(ids){
		if(!isNaN(ids)){
		    _this.removeTableTr(_this.setting.tableId+"_"+ids);
		}else{
			var array = ids.split(",");
			for (x in array)
			{
				var id = array[x];
			    _this.removeTableTr(_this.setting.tableId+"_"+id);
			}
		}
	}
	this.removeItemAfter=function(id){
		if(!isNaN(ids)){
		    var trObj = $("#"+_this.setting.tableId+"_"+ids);
		    $("#"+_this.setting.tableId+"_"+id+"_"+"validModDt").text(_this.getNowFormatDate());
	
		}else{
			var array = ids.split(",");
			for (x in array)
			{
				var id = array[x];
				var trObj = $("#"+_this.setting.tableId+"_"+id);
				$("#"+_this.setting.tableId+"_"+id+"_"+"validModDt").text(_this.getNowFormatDate());
			}
		}
	};
	this.updateItemAfter = function(result,para){
		 if(result && result.data){
			 var data = result.data;
			 var trObj = $("#"+data.id);
			 for ( var name in data ){ // 方法
				 var value = data[name];
				 if(value==null){
					value = "";
				 }
				 $(trObj.find("."+name)).text(value);
			 }
		 }
	}
	this.addItemAfter = function(result,para){
		//TODO 添加
		_this.search();
	}
	this.initTable = function(){
		_this.controllerInit($('#'+_this.setting.tableId+' >tbody > tr > td input[name=validClass]'));
		_this.controllerInit($('#'+_this.setting.tableId+' >tbody > tr > td input[name=deleteClass]'),false);
	}
	this.init = function(){//初始化
		_this.initEvent();
		_this.renderAfterEvent();
		_this.renderAfterEventOther();
		_this.initTable();
	}
}

//jQuery(function($) {
//	
//	//页面初始化
//	pageContext.init();
//	
//});